//
//  SDLoadingView.m
//  SKinDiary
//
//  Created by pcyang on 16/6/26.
//  Copyright © 2016年 tencent. All rights reserved.
//

#import "SDLoadingView.h"

#define  kLoaingViewTag     10267

@interface SDLoadingView()
@end

@implementation SDLoadingView

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

+(void)showLoadingWithSuperView:(UIView*) superView frame:(CGRect) frm withAnimated:(BOOL) animated
{
    UIView *view = [superView viewWithTag:kLoaingViewTag];
    if (view)
    {
        return;
    }
    else
    {
        view = [[UIView alloc] initWithFrame:frm];
        view.tag = kLoaingViewTag;
        view.backgroundColor = [UIColor whiteColor];
        
        [superView addSubview:view];
        NSMutableArray *bflies = [NSMutableArray array];
        
        for (int i = 1; i <= 12; i++)
        {
            NSString *name = [NSString stringWithFormat:@"feixiang_80_%d.png",i];
            UIImage *image = LOAD_IMAGE_USE_CACHE_INBUNDLE(DefaultBundle, name);;
            [bflies addObject:image];
        }
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 512/2, 61)];
        imageView.animationImages = bflies;
        imageView.animationDuration = 1.17f;
        [imageView startAnimating];
        [view addSubview:imageView];
        imageView.center = CGPointMake(view.width/2, view.height/2);
    }
}

+(void)showLoadingWithSuperView:(UIView*) superView rect:(CGRect)rect withAnimated:(BOOL) animated
{
    [SDLoadingView showLoadingWithSuperView:superView  withAnimated:animated];
    UIView *view = [superView viewWithTag:kLoaingViewTag];
    view.frame = rect;
}

+(void)showLoadingWithSuperView:(UIView*) superView withAnimated:(BOOL) animated
{
    UIView *view = [superView viewWithTag:kLoaingViewTag];
    if (view)
    {
        return;
    }
    else
    {
        view = [[UIView alloc] initWithFrame:superView.bounds];
        view.tag = kLoaingViewTag;
        view.backgroundColor = [UIColor whiteColor];
        
        [superView addSubview:view];
        
        NSMutableArray *bflies = [NSMutableArray array];
        
        for (int i = 1; i <= 12; i++)
        {
            NSString *name = [NSString stringWithFormat:@"feixiang_80_%d.png",i];
            UIImage *image = LOAD_IMAGE_USE_CACHE_INBUNDLE(DefaultBundle, name);;
          //  [bflies addObject:image];
        }
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 512/2, 61)];
        imageView.animationImages = bflies;
        imageView.animationDuration = 1.17f;
        [imageView startAnimating];
        [view addSubview:imageView];
        imageView.center = view.center;
    }
}

+(void)hideLoadingFromSuperView:(UIView*) superView withAnimted:(BOOL) animated
{
    UIView *view = [superView viewWithTag:kLoaingViewTag];
    if (view)
    {
        [view removeFromSuperview];
        view = nil;
    }
}

@end
